//package org.ricks.router;
//
//import org.ricks.ioc.TaskBus;
//import org.ricks.common.lang.Logger;
//import org.ricks.net.tcp.CmdKit;
//import org.ricks.common.utils.DateUtils;
//import org.ricks.ioc.RicksContext;
//import org.ricks.net.*;
//import org.ricks.net.rpc.AskPackage;
//import org.ricks.protocol.ProtocolManager;
//
//import java.io.IOException;
//import java.util.Set;
//import java.util.concurrent.Executor;
//import java.util.concurrent.ExecutorService;
//import java.util.concurrent.Executors;
//import java.util.function.Consumer;
//
//public class TcpClient {
//
//    static ExecutorService executor = Executors.newFixedThreadPool(16);
//
//    public static void main(String[] args) throws IOException {
//        ProtocolManager.initProtocolAuto(Set.of(InnerMessage.class, AskPackage.class,RpcTestPakcet.class));
//        RicksContext.me().init();
//        NetContext.me().init();
//        TcpInnerProtocol innerProtocol = new TcpInnerProtocol();
//        ClientHandler innerHandler = new ClientHandler();
//
//        AioClient client = new AioClient("127.0.0.1",9100, innerProtocol, innerHandler);
//
//        AioSession aioSession = client.start();
//
//
//        Consumer<AskPackage> action  = (AskPackage rpcPackage) -> {
//            Object packet = rpcPackage.getPacket();
////            System.err.println(Thread.currentThread().getName() + " , " + rpcPackage.getReqId());
//        };
//        int rpcCmd = CmdKit.merge((short) 0, (short)2502);
//        long startTime = System.nanoTime();
//
//        for (int i = 0; i < 20_0000 ; i++) {
//            AskPackage askPackage = AskPackage.valueOf(aioSession.nextReqId(),rpcCmd, null);
//            Router.me().syncAsk(aioSession, askPackage ,askPackage1 -> {});
//        }
//        float interval = DateUtils.formatNanoTime(System.nanoTime() - startTime);
//        Logger.info("rpc sync call to ofVirtual 200000 , exec="+interval+" ms");
//
//
////        long startTime1 = System.nanoTime();
////
////        for (int i = 0; i < 1 ; i++) {
////            AskPackage askPackage2 = AskPackage.valueOf(aioSession.nextReqId(),rpcCmd, null);
////
////            Router.me().syncAsk(aioSession, askPackage2,null  );
////
////            System.err.println(".....");
////        }
////        float interval1 = DateUtils.formatNanoTime(System.nanoTime() - startTime1);
////        Logger.info("rpc sync call to curr Thread 200000 , exec="+interval1+" ms");
//
//
//        long startTime2 = System.nanoTime();
//
//        Executor taskExecutor = TaskBus.currentThreadExecutor();
//        for (int i = 0; i < 20_0000 ; i++) {
//            AskPackage askPackage = AskPackage.valueOf(aioSession.nextReqId(),rpcCmd, null);
////            DefaultContext defaultContext = new DefaultContext(aioSession,  askPackage);
//            Thread.ofVirtual().start(() -> {
//                Router.me().syncAsk(aioSession, askPackage, rpcPackage -> {
//                    System.err.println(Thread.currentThread().getName() + ": 你好，i am & " + rpcPackage.getReqId());
//                });
//            });
//
//        }
//        float interval2 = DateUtils.formatNanoTime(System.nanoTime() - startTime2);
//        Logger.info("rpc sync call to ask1 200000 , exec="+interval2+" ms");
//    }
//}
